package com.ucar.training.controller;

import com.ucar.training.domain.User;
import com.ucar.training.service.IUserService;
import com.ucar.training.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author XiongMM
 * @date 2019/7/29 11:16
 * @description
 */
public class AjaxServlet extends HttpServlet {

    private IUserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //得到拼接的数据
        String userName = req.getParameter("userName");
        User user = userService.selectOne(userName);
        //如果存在
        if (user != null) {
            //进行响应，返回数据
            resp.getWriter().print(true);
        } else {
            resp.getWriter().print(false);
        }
    }
}
